show engines;# 查看mysql的存储引擎

create table count (
	id bigint primary key auto_increment,
	name varchar(20) unique,
	balance int
	);

select * from count;

insert into count values (1, '张三', 1000),(2, '李四', 1000); 

select * from count;
#开启事务start transaction;或者begin;
begin;

select * from count;

rollback;#回滚事务 或者commit提交事务

start transaction;

#设置保存点
#保存点1
savepoint point1;
#保存点2
savepoint point2;

#回滚到保存点2
rollback to point2;

#全部回滚
rollback;

show variables like 'autocommit';#autocommit是一个系统变量标识事务是否自动提交

#设置不自动提交
set autocommit = 0;

show variables like 'autocommit';

insert into count values (3, '王五', 2000);

select * from count;

rollback;

select * from count;

set autocommit = 1;

#global全局作用域(session当前会话生效只作用于下一个事务)
select @@global.transaction_isolation;

set global transaction isolation level read uncommitted;#最低级的隔离 读未提交

select @@global.transaction_isolation;

begin;

insert into count values (3, '王五', 2000);

commit;


set global transaction_isolation = 'read-committed';#读已提交

select @@global.transaction_isolation;

set global transaction isolation level repeatable read;#可重复度

select @@global.transaction_isolation;

set global transaction isolation level serializable;#序列化串行化

select @@global.transaction_isolation;
